﻿<Page
    x:Class="App12.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App12"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.DataContext>
        <local:MainPageViewModel Letter="C" />
    </Page.DataContext>

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="140" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <ListView x:Name="MyList" ItemsSource="{Binding Letters}" 
                  ItemTemplate="{StaticResource MyContentControl}"
                  SelectedItem="{Binding Letter, Mode=TwoWay}" />
        <ListView Grid.Column="1" ItemsSource="{Binding Numbers}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <StackPanel.Resources>
                            <local:MyControlViewModel 
                                x:Key="MyDataContext" Number="{Binding}" 
                                Letters="{Binding ItemsSource, ElementName=MyList}" 
                                Letter="{Binding SelectedItem, ElementName=MyList}" />
                        </StackPanel.Resources>
                        <local:MyControl DataContext="{StaticResource MyDataContext}" />
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</Page>
